package main

import (
	"encoding/json"
	"fmt"
	"net/http"
	"nh-poc/pkg/common"

	"github.com/gin-gonic/gin"
)

func main() {
	fmt.Println("ali-parks-service is start.")
	//gin.SetMode(gin.ReleaseMode)
	// 创建一个默认的 Gin 路由器
	r := gin.Default()

	// 定义一个 GET 路由
	r.GET("/", func(c *gin.Context) {
		c.JSON(http.StatusOK, gin.H{
			"msg": "Hello, 阿里园区系统",
		})
	})

	// 定义事件上报接口
	r.POST("/reportRecv", func(c *gin.Context) {
		header := c.Request.Header
		response := common.ParkResponse{
			Data: common.HKEvent{},
		}
		if err := c.ShouldBindJSON(&response); err != nil {
			c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
			return
		}

		buf, err := json.Marshal(response)
		if err != nil {
			c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
			return
		}
		fmt.Println("header:", header)
		fmt.Printf("event=%s\n", string(buf))

		c.JSON(http.StatusOK, gin.H{
			"msg": "reportRecv is ok.",
		})
	})

	r.Run(":9090")

}
